﻿/* Developed by Aknazarov Zagir aknzarov@gmail.com */

using System;

namespace SimpleDayView
{
	public class GridCell : IComparable<GridCell>, IEquatable<GridCell>
	{
		public int CellIndex { get; set; }
			
		public DateTime Time { get; set; }
			
		public bool IsOneColumn(GridCell cell)
			{			
				if(CellIndex != cell.CellIndex)
					return false;
			
				if(Time.Day != cell.Time.Day)
					return false;
				
				if(Time.Month != cell.Time.Month)
					return false;
				
				if(Time.Year != cell.Time.Year)
					return false;
			
				return true;
			}
			
		public int Compare(GridCell x, GridCell y)
			{
				if (x.CellIndex != y.CellIndex)
					return x.CellIndex.CompareTo(y.CellIndex);
				
				if(x.Time.Minute != y.Time.Minute)
					return x.Time.Minute.CompareTo(y.Time.Minute);
				
				if(x.Time.Hour != y.Time.Hour)
					return x.Time.Hour.CompareTo(y.Time.Hour);				
				
				if(x.Time.Day != y.Time.Day)
					return x.Time.Day.CompareTo(y.Time.Day);
				
				if(x.Time.Month != y.Time.Month)
					return x.Time.Month.CompareTo(y.Time.Month);
				
				if(x.Time.Year != y.Time.Year)
					return x.Time.Year.CompareTo(y.Time.Year);
				
				return 0;
			}
		
		public int CompareTo(GridCell other)
		{
			if (CellIndex != other.CellIndex)
				return CellIndex.CompareTo(other.CellIndex);
			
			if(Time.Year != other.Time.Year)
				return Time.Year.CompareTo(other.Time.Year);
			
			if(Time.Month != other.Time.Month)
				return Time.Month.CompareTo(other.Time.Month);
			
			if(Time.Day != other.Time.Day)
				return Time.Day.CompareTo(other.Time.Day);
						
			if(Time.Hour != other.Time.Hour)
				return Time.Hour.CompareTo(other.Time.Hour);
			
			if (Time.Minute != other.Time.Minute)
				return Time.Minute.CompareTo(other.Time.Minute);
															
			return 0;
		}
		
		public bool Equals(GridCell other)
		{
			if (CellIndex != other.CellIndex)
				return false;
				
			if(Time.Day != other.Time.Day)
				return false;
				
			if(Time.Month != other.Time.Month)
				return false;
				
			if(Time.Year != other.Time.Year)
				return false;
			
			if(Time.Hour != other.Time.Hour)
				return false;
			
			if(Time.Minute != other.Time.Minute)
				return false;
				
			return true;
		}
	}
}
